// app/controller/news.js
const Controller = require('egg').Controller;

class NewsController extends Controller{
    /**
     * 获取新闻列表
     * @returns {Promise<void>}
     */
    async list() {
        const dataList = {
            list: [
                { id: 1, title: 'this is news 1', url: '/news/1' },
                { id: 2, title: 'this is news 2', url: '/news/2' }
            ]
        };
        await this.ctx.render('news/list.tpl', dataList);
    }

    /**
     * 根据service获取数据
     * @returns {Promise<void>}
     */
    async list2(){
        const ctx = this.ctx;
        const page = ctx.query.page || 1;
        const newsList = await ctx.service.news.list(page);
        await ctx.render('news/list2.tpl', { list: newsList });
    }
}


module.exports = NewsController;
